export default{
    handleNum (val) {//处理数字过万
        let num = 0
        if (val > 9999) {
            num = Math.round(val / 10000 * 10) / 10 + '万'
        } else {
            num = val
        }

        return num
    },
    handleSongTime(duration=0){  //处理歌曲时长，格式化时间格式为04：05或者12：31
        duration = duration/1000;
        const m = (""+Math.floor(duration/60)).padStart(2,'0');
        const s = (""+Math.floor(duration%60)).padStart(2,'0');
        return `${m}:${s}`
    },
     getSongDate(duration,isshow=false,conF={year:'年',month:'月',day:'日'}) { //格式化时间戳
        const dt = new Date(duration);
        const opt = {
            yy: dt.getFullYear(),
            MM: (dt.getMonth() + 1 + '').padStart(2, '0'),
            dd: (dt.getDate() + '').padStart(2, '0'),
            HH: (dt.getHours() + '').padStart(2, '0'),
            mm: (dt.getMinutes() + '').padStart(2, '0'),
            ss: (dt.getSeconds() + '').padStart(2, '0')
        }
        const {yy,MM,dd,HH,mm} = opt;
        const {year,month,day}=conF;
        if(isshow){
            return yy+'-'+MM+'-'+dd
        }else{
            return yy+year+MM+month+dd+day
        }
    },
    handleFont(val){  //处理文字过长
        if(val.length>15){
            return val.slice(0,15).padEnd(19,' ...')
        }
        else{
            return val
        }
    },
    concatPlayList(newList=[],oldList=[]){  //合并新老数组，并去重
        const arrList = [...oldList,...newList];
    return [...arrList.reduce((pre,next)=>{
            !pre.has(next.id)?pre.set(next,next.id):''
             return pre
        },new Map()).keys()]}
}